qui(
    function (require, exports, module) {
        WrapSys.MarkOcrManager ={
            doMarkOcrImage: function () {
                $("#image_mark-dlg").dialog("open");
                WrapSys.MarkOcrManager.doMarkOcrImageReset();
                var imageId = parseInt($(".red").parent().find(".pid").html());
                var paramsData = WrapSys.Dao.getParamsData();
                var data = {
                    image_id: imageId,
                    channel_code: paramsData.channel_name,
                    from_client: true,
                    key: WrapSys.Dao.settings.taskid
                };
                //_channel_id
                WrapSys.Dao.getOcrImage(data, function (rdata) {
                    if (rdata != null && rdata.code == "A00000") {
                        var tempHandler = function (rdata2) {
                            if (rdata2 != null && rdata2.code == "A00000") {
                                $("#ocr_image_div").show();
                                $("#ocr_image").attr("src", rdata2.uri);
                                WrapSys.Config.CropInstance.setImage(rdata2.uri);
                                console.log("  doMarkOcrImage suc")
                            } else {
                                $("input[name=image_location]").val(rdata2 == null ? "无数据" : rdata2.msg);
                                WrapSys.Plugin.tips("error", WrapSys.Config.REMIND_MSG_INFO.GET_IMG_FAIL);
                                WrapSys.Util.logSubmit(WrapSys.Config.VOD_LOG_TYPE.getImageData, data, {error: WrapSys.Config.REMIND_MSG_INFO.GET_IMG_FAIL}, WrapSys.Dao.getDotData().findImage);
                                WrapSys.Util.notifyAlert(WrapSys.Config.REMIND_MSG_INFO.GET_IMG_FAIL + ";" + WrapSys.Dao.getDotData().ocrimage + "|" + JSON.stringify(data).replace(/"/g, ""));
                            }
                        }
                        if(WrapSys.Config.READ_IMAGE_METHOD == "new"){
                            WrapSys.Dao.doFindImage("ocr_image", data, tempHandler)
                        }else{
                            tempHandler(rdata);
                        }
                    } else {
                        WrapSys.Plugin.tips("error", "请求图片失败!");
                    }
                })
            },
            doMarkOcrImageReset: function () {
                $("#ocr_image_div").hide();
                $("input[name=image_ocr_title]").val("");
                $("input[name=origin_ocr_title]").val("");
                $("input[name=image_ocr_title]").change();
                $("input[name=image_location]").val("");
                WrapSys.Config.OCR_RESULT_CALL = false;
            },
            fillByOcrTitle: function () {
                if (WrapSys.Config.OCR_RESULT_CALL) {
                    WrapSys.Config.OCR_TITLE_FLAG = 1;
                    VODCom.AutoTitle.AUTO_TITLE_FLAG = 0;
                    // 关联用户选定的
                    VODCom.AutoTitle.USER_TITLE_SELECT = parseInt($(".red").parent().find(".pid").html())
                }
                WrapSys.Config.OCR_TITLE_ORIGIN = $("input[name=origin_ocr_title]").val();
                var title = $("input[name=image_ocr_title]").val();
                if (title.trim().length > 0) {
                    $("input[name=videoName]").val(title.trim());
                    $("input[name=videoName]").change();
                }
            },
            doCropChange: function (obj) {

            },
            doCropSelect: function (obj) {
                console.log("doCropSelect " + JSON.stringify(obj));
                var scale = 1;
                var showObj = {
                    x: parseInt(obj.x / scale),
                    y: parseInt(obj.y / scale),
                    w: Math.ceil(obj.w / scale),
                    h: Math.ceil(obj.h / scale)
                };
                console.log("doCropSelect " + JSON.stringify(obj) + "," + JSON.stringify(showObj))
                $("input[name=image_location]").val(JSON.stringify(showObj));
                WrapSys.MarkOcrManager.reqOcrResult(showObj);
            },
            reqOcrResult: function (obj) {
                var imageId = parseInt($(".red").parent().find(".pid").html());
                var paramsData = WrapSys.Dao.getParamsData();
                var data = {
                    image_id: imageId,
                    channel_code: paramsData.channel_name,
                    from_client: true,
                    key: WrapSys.Dao.settings.taskid,
                    x: obj.x,
                    y: obj.y,
                    w: obj.w,
                    h: obj.h
                };
                WrapSys.Dao.getOcrResult(data, function (rData) {
                    console.log("getOcrResult:" + rData == null ? "" : JSON.stringify(rData));
                    if (rData != null && rData.code == "A00000") {
                        rData.result = rData.result.trim();
                        $("input[name=image_ocr_title]").val(rData.result);
                        $("input[name=origin_ocr_title]").val(rData.result);
                        WrapSys.Config.OCR_RESULT_CALL = true;
                    } else {
                        $("input[name=image_ocr_title]").val("");
                        $("input[name=origin_ocr_title]").val("");
                        WrapSys.Plugin.tips("error", "识别标题失败!");
                        WrapSys.Util.logSubmit(WrapSys.Config.VOD_LOG_TYPE.submitOcrTitleData, data, {error: "识别标题失败!"}, $("#ocr_image").attr("src"));
                        WrapSys.Util.notifyAlert("ocr识别标题失败:" + $("#ocr_image").attr("src") + "|" + JSON.stringify(data).replace(/"/g, ""));
                    }
                    $("input[name=image_ocr_title]").change();
                })
            }
        }
    }
);